﻿using System;
using System.Collections.Generic;

namespace TraceThisItem.Domain
{
	public class User
	{
		#region Properties

		public string UserName { get; set; }

		public string Firstname { get; set; }

		public string Lastname { get; set; }

		#endregion Properties

		#region Navigation properties

		public virtual ICollection<Team> Teams { get; set; }

		public virtual ICollection<Project> OwnedProjects { get; set; }

		#endregion Navigation properties

		public string FullName
		{
			get
			{
				return this.ToString();
			}
		}

		public User()
		{
			this.Teams = new List<Team>();
		}

		#region Overriden methods

		/// <summary>
		/// Determina si este usuario es igual a otro usuario.
		/// </summary>
		/// <param name="obj">Usuario a comprobar contra el actual.</param>
		/// <returns>True si ambos usuarios son iguales.</returns>
		public override bool Equals(object obj)
		{
			if (obj == null || GetType() != obj.GetType())
			{
				return false;
			}

			return this.UserName.Equals(((User)obj).UserName);
		}

		/// <summary>
		/// Obtiene un valor hash que representa al usuario.
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			return this.UserName.GetHashCode();
		}

		/// <summary>
		/// Retorna la representación del usuario como cadena.
		/// </summary>
		/// <returns>Nombre de usuario.</returns>
		public override string ToString()
		{
			return String.Format("{0} {1}", this.Firstname, this.Lastname);
		}

		#endregion Overriden methods
	}
}